<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="../../static/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="../../static/css/admin.css" media="all">
    <style>
    </style>
</head>
<body>

<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-form layui-card-header layuiadmin-card-header-auto" style="border-radius: 0;border-top: 4px solid #d2d2d2;">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label" style="margin-left: -40px!important;">档案编号</label>
                    <div class="layui-input-inline">
                        <input type="text" name="archives_id" placeholder="请输入档案编号" autocomplete="off" class="layui-input"style="width: 72%">
                    </div>
                </div>
                <div class="layui-inline" style="margin-left: -115px">
                    <label class="layui-form-label">审核状态</label>
                    <div class="layui-input-inline" style="width: 100px!important;">
                        <select name="audit_status">
                            <option value=""></option>
                            <option value="起草">起草</option>
                            <option value="审核中">审核中</option>
                            <option value="审核通过">审核通过</option>
                            <option value="驳回">驳回</option>
                            <option value="变更">变更</option>
                            <option value="变更审核中">变更审核中</option>
                        </select>
                    </div>
                </div>
                <div class="layui-inline" style="margin-left: -60px">
                    <label class="layui-form-label">档案状态</label>
                    <div class="layui-input-inline"style="width: 100px!important;">
                        <select name="status" >
                            <option value=""></option>
                            <option value="试用期">试用期</option>
                            <option value="正式员工">正式员工</option>
                            <option value="离职">离职</option>
                            <option value="已删除">已删除</option>
                            <option value="实习员工">实习员工</option>
                        </select>
                    </div>
                </div>
                <div class="layui-inline" style="margin-left: -60px">
                    <label class="layui-form-label">验证日期</label>
                    <div class="layui-input-inline layui-input-wrap">
                        <div class="layui-input-prefix">
                            <i class="layui-icon layui-icon-date"></i>
                        </div>
                        <input type="text" name="s_date" id="s_date" placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline" style="margin-left: -100px!important;">
                    <label class="layui-form-label">至</label>
                    <div class="layui-input-inline layui-input-wrap">
                        <div class="layui-input-prefix">
                            <i class="layui-icon layui-icon-date"></i>
                        </div>
                        <input type="text" name="t_date" id="t_date" placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <button class="layui-btn layuiadmin-btn-useradmin" lay-submit lay-filter="LAY-emp-front-search">
                        <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                    </button>
                </div>
            </div>
        </div>
        <div class="layui-card-body">
            <div style="padding-bottom: 10px;">
                <button class="layui-btn layuiadmin-btn-useradmin" data-type="add">档案登记</button>
            </div>

            <table id="LAY-user-manage" lay-filter="LAY-user-manage"></table>

            <script type="text/html" id="table-useradmin-webuser">
                <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit"><i class="layui-icon layui-icon-edit"></i>修改</a>
                <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="detail"><i class="layui-icon layui-icon-edit"></i>明细</a>
                <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i class="layui-icon layui-icon-delete"></i>删除</a>
            </script>

            <!--  日期格式化处理 -->
            <script type="text/html" id="set_timeTpl">
                {{formatDate(d.set_time)}}
            </script>

        </div>
    </div>
</div>

<!--<script src="js/jquery-2.0.3.min.js"></script>-->
<script src="../../static/layui/layui.js"></script>
<script type="text/javascript">

    layui.use(['layer','table','form','element','util'], function(){
        var $ = layui.$
            ,form = layui.form
            ,layer = layui.layer
            ,table = layui.table
            ,element = layui.element
            ,util = layui.util
//头部事件
        util.event('lay-header-event', {
            //左侧菜单事件
            menuLeft: function(othis){
                layer.msg('展开左侧菜单的操作', {icon: 0});
            }
            ,menuRight: function(){
                layer.open({
                    type: 1
                    ,content: '<div style="padding: 80px;">处理右侧面板的操作</div>'
                    ,area: ['230px', '50%']
                    ,offset: 'rt' //右上角
                    ,anim: 5
                    ,shadeClose: true
                });
            }
        });
        //加载table
        table.render({
            elem: '#LAY-user-manage'
            ,url:'/archives/findAllArchives' //后端接口
            ,cellMinWidth: 100 //全局定义常规单元格的最小宽度
            ,title: '雇员数据表'
            ,cols: [[
                 {field:'archives_id',title:'档案编码',align:'center'}
                ,{field:'name', title:'姓名',align:'center'}
                ,{field:'sex', title:'性别',align:'center'}
                ,{field:'degree', title:'学历',align:'center'}
                ,{field:'dept_full_name', title:'所属部门',align:'center',width: 130}
                ,{field:'job_name',title:'职位',align:'center'}
                ,{field:'job_title_name', title:'职称',align:'center'}
                ,{field:'set_time', title:'建档日期',align:'center',width: 130,templet: '#time'}
                ,{field:'audit_status', title:'审核状态',align:'center'}
                ,{field:'status', title:'档案状态',align:'center'}
                ,{fixed: 'right', title:'操作', toolbar: '#table-useradmin-webuser',width:250}
            ]]
            ,page: {
                curr: 1 //设定初始在第 5 页
                ,limit: 5 //设定初始每页显示 5 条
            },
            limits:[5,10,15,20]
        });
        //监听行工具事件
        table.on('tool(LAY-user-manage)', function(obj){
            var data = obj.data;
            //console.log(obj)
            if(obj.event === 'del'){
                layer.confirm('真的删除行么', function(index){
                    $.ajax({
                        url:"/archives/del", //请求后端接口地址
                        type:"post", //请求方式get | post
                        data:{archives_id:data.archives_id}, //提交json字符串对象参数
                        dataType:"json", //后端返回参数类型
                        success:function (res){ //请求成功后回调函数res = JSONObject.toJSONString(resultMap)
                            if(res.code == 0){//成功
                                layer.msg(res.msg);//弹出提示
                                table.reload('LAY-user-manage'); //数据刷新
                                layer.close(index); //关闭弹层
                            }
                            if(res.code == -1){//系统出问题
                                layer.msg(res.msg,{icon: 5});//弹出提示
                            }
                        }
                    })
                });
                //详情按钮
            }else if(obj.event === 'detail'){
                layer.open({
                    type: 2
                    ,title: '登记档案信息'
                    ,skin: 'layui-layer-molv'
                    ,content: 'vita.html'
                    ,maxmin: true
                    ,area: ['480px', '570px']
                    ,success: function (layero,index){
                        var body = layer.getChildFrame("body",index);
                        //禁用框体
                        body.find('input').prop('readonly',true);
                        body.find('select').prop('disabled',true);
                        body.find('textarea').prop('disabled',true);
                        $("input[type=date]").prop('disabled',true);
                        var contentWindow = layero.find('iframe')[0].contentWindow;//得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
                        body.find("select[name=dept_full_name]").val(data.dept_full_name);
                        body.find("select[name=status]").val(data.status);
                        body.find("select[name=job_name]").val(data.job_name);
                        body.find("input[name=job_id]").val(data.job_id);
                        body.find("input[name=name]").val(data.name);
                        body.find("input[name=archives_id]").val(data.archives_id);
                        body.find("select[name=sex]").val(data.sex);
                        body.find("input[name=email]").val(data.email);
                        body.find("input[name=phone]").val(data.phone);
                        body.find("input[name=address]").val(data.address);
                        body.find("input[name=identity]").val(data.identity);
                        body.find("input[name=location]").val(data.location);
                        body.find("input[name=politic_outlook]").val(data.politic_outlook);
                        body.find("input[name=graduate_school]").val(data.graduate_school);
                        body.find("input[name=major]").val(data.major);
                        body.find("select[name=degree]").val(data.degree);
                        body.find("select[name=sal_standard_name]").val(data.sal_standard_name);
                        body.find("input[name=bank]").val(data.bank);
                        body.find("input[name=count]").val(data.count);
                        body.find("input[name=security_card_number]").val(data.security_card_number);
                        body.find("input[name=regist]").val(data.regist);
                        var originalDate = data.set_time; // 假设data.set_time是从后端获取的原始日期数据
                        var date = new Date(originalDate);
                        var year = date.getFullYear();
                        var month = (date.getMonth() + 1).toString().padStart(2, '0');
                        var day = date.getDate().toString().padStart(2, '0');
                        var formattedDate = `${year}-${month}-${day}`;
                        body.find("input[name=set_time]").val(formattedDate);
                        body.find("textarea[name=resume]").val(data.resume);
                        body.find("textarea[name=relationship]").val(data.relationship);
                        body.find("textarea[name=remark]").val(data.remark);
                    }
                    ,btn: ['取消']
                });

            }else if (obj.event==='edit'){
                layer.open({
                    type: 2
                    , title: '修改档案信息'
                    , skin: 'layui-layer-molv'
                    , content: 'vita.html'
                    , maxmin: true
                    , area: ['480px', '570px']
                    ,success: function (layero,index){
                        var body = layer.getChildFrame("body",index);
                        //禁用框体
                        var contentWindow = layero.find('iframe')[0].contentWindow;//得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
                        body.find("select[name=dept_full_name]").val(data.dept_full_name);
                        body.find("select[name=status]").val(data.status);
                        body.find("select[name=job_name]").val(data.job_name);
                        body.find("input[name=job_id]").val(data.job_id);
                        body.find("input[name=name]").val(data.name);
                        body.find("input[name=archives_id]").val(data.archives_id);
                        body.find("select[name=sex]").val(data.sex);
                        body.find("input[name=email]").val(data.email);
                        body.find("input[name=phone]").val(data.phone);
                        body.find("input[name=address]").val(data.address);
                        body.find("input[name=identity]").val(data.identity);
                        body.find("input[name=location]").val(data.location);
                        body.find("input[name=politic_outlook]").val(data.politic_outlook);
                        body.find("input[name=graduate_school]").val(data.graduate_school);
                        body.find("input[name=major]").val(data.major);
                        body.find("select[name=degree]").val(data.degree);
                        body.find("select[name=sal_standard_name]").val(data.sal_standard_name);
                        body.find("input[name=bank]").val(data.bank);
                        body.find("input[name=count]").val(data.count);
                        body.find("input[name=security_card_number]").val(data.security_card_number);
                        body.find("input[name=regist]").val(data.regist);
                        var originalDate = data.set_time; // 假设data.set_time是从后端获取的原始日期数据
                        var date = new Date(originalDate);
                        var year = date.getFullYear();
                        var month = (date.getMonth() + 1).toString().padStart(2, '0');
                        var day = date.getDate().toString().padStart(2, '0');
                        var formattedDate = `${year}-${month}-${day}`;
                        body.find("input[name=set_time]").val(formattedDate);
                        body.find("textarea[name=resume]").val(data.resume);
                        body.find("textarea[name=relationship]").val(data.relationship);
                        body.find("textarea[name=remark]").val(data.remark);
                        console.log(data.dept_full_name)
                    }
                    , btn: ['确定', '取消']
                    , yes: function (index, layero) {
                        var iframeWindow = window['layui-layer-iframe' + index]
                            , submitID = 'LAY-user-front-submit'
                            , submit = layero.find('iframe').contents().find('#' + submitID);
                        //监听提交
                        iframeWindow.layui.form.on('submit(' + submitID + ')', function (data) {
                            var field = data.field; //获取提交的字段
                            $.ajax({
                                url: "/archives/update", //请求后端接口地址
                                type: "post", //请求方式get | post
                                data: JSON.stringify(field), //提交json字符串对象参数
                                contentType: "application/json;charset=utf-8", //发送信息至服务器时内容编码类型
                                dataType: "json", //后端返回参数类型
                                success: function (res) { //请求成功后回调函数res = JSONObject.toJSONString(resultMap)
                                    if (res.code == 0) {//成功
                                        layer.msg(res.msg);//弹出提示
                                        table.reload('LAY-user-manage'); //数据刷新
                                        layer.close(index); //关闭弹层
                                    }
                                    if (res.code == -1) {//系统出问题
                                        layer.msg(res.msg, {icon: 5});//弹出提示
                                    }
                                }
                            })
                        });
                        submit.trigger('click');
                    }
                });
            }
        });


        //监听搜索
        form.on('submit(LAY-emp-front-search)', function(data){
            var field = data.field;
            // 调用后端接口，传递参数
            table.reload('LAY-user-manage', {
                url:"/archives/search", //后端搜索接口URL地址
                where: field
            });
        });


        //事件
        var active = {
           add: function(){
                layer.open({
                    type: 2
                    ,title: '登记档案信息'
                    ,skin: 'layui-layer-molv'
                    ,content: 'vita.html'
                    ,maxmin: true
                    ,area: ['1316px', '652px']
                    ,btn: ['确定', '取消']
                    ,yes: function(index, layero){
                        var iframeWindow = window['layui-layer-iframe'+ index]
                            ,submitID = 'LAY-user-front-submit'
                            ,submit = layero.find('iframe').contents().find('#'+ submitID);
                        //监听提交
                        iframeWindow.layui.form.on('submit('+ submitID +')', function(data){
                            var field = data.field; //获取提交的字段
                            console.log(field)
                            $.ajax({
                                url:"/archives/addArchives", //请求后端接口地址
                                type:"post", //请求方式get | post
                                data:JSON.stringify(field), //提交json字符串对象参数
                                contentType:"application/json;charset=utf-8", //发送信息至服务器时内容编码类型
                                dataType:"json", //后端返回参数类型
                                success:function (res){ //请求成功后回调函数res = JSONObject.toJSONString(resultMap)
                                    if(res.code == 0){//成功
                                        layer.msg(res.msg);//弹出提示
                                        table.reload('LAY-user-manage'); //数据刷新
                                        layer.close(index); //关闭弹层
                                    }
                                    if(res.code == -1){//系统出问题
                                        layer.msg(res.msg,{icon: 5});//弹出提示
                                    }
                                }
                            })
                        });
                        submit.trigger('click');
                    }
                });
            }
        };
        $('.layui-btn.layuiadmin-btn-useradmin').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

    });
</script>
<script src="../../static/layui/layui.js"></script>

<script>
    layui.use(['form', 'laydate', 'util'], function(){
        var form = layui.form;
        var layer = layui.layer;
        var laydate = layui.laydate;
        var util = layui.util;
        // 日期
        laydate.render({
            elem: '#t_date'
        });
        // 日期
        laydate.render({
            elem: '#s_date'
        });
    });
</script>
<!--限制时间格式-->
<script type="text/html" id="time">
    {{# if(d.set_time !== undefined && d.set_time !== null && d.set_time !== ''){ }}
    {{ layui.util.toDateString(d.set_time, 'yyyy-MM-dd') }}
    {{# }}}
</script>
</body>
</html>